﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.TMS.EasyMoveSuiteConfig;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.TMS.EasyMoveSuiteConfig;

namespace BCTMSRESTful.Controllers.Management.TMS.EasyMoveSuiteConfig
{
    /// <summary>
    /// 便捷搬家套餐配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class EasyMoveSuiteConfigController : ManagementBaseController
    {
        private readonly IEasyMoveSuiteConfigService easyMoveSuiteConfigService;

        public EasyMoveSuiteConfigController(IEasyMoveSuiteConfigService easyMoveSuiteConfigService)
        {
            this.easyMoveSuiteConfigService = easyMoveSuiteConfigService;
        }

        #region 添加便捷搬家套餐配置
        /// <summary>
        ///  添加便捷搬家套餐配置
        /// </summary>
        /// <param name="requestDto">便捷搬家套餐配置信息</param>
        /// <response code="201">添加便捷搬家套餐配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加便捷搬家套餐配置")]
        [ProducesResponseType(typeof(EasyMoveSuiteConfigDto), 201)]
        public IActionResult Post(
            [FromBody] EasyMoveSuiteConfigRequestDto requestDto)
        {
            var result = this.easyMoveSuiteConfigService.Add(this.Admin, requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改便捷搬家套餐配置
        /// <summary>
        ///  修改便捷搬家套餐配置
        /// </summary>
        /// <param name="easyMoveSuiteConfigId">便捷搬家套餐配置Id</param>
        /// <param name="requestDto">便捷搬家套餐配置信息</param>
        /// <response code="200">修改便捷搬家套餐配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{easy_move_suite_config_id}")]
        [Log("修改便捷搬家套餐配置")]
        [ProducesResponseType(typeof(EasyMoveSuiteConfigDto), 200)]
        public IActionResult Put([FromRoute(Name = "easy_move_suite_config_id")] int easyMoveSuiteConfigId, [FromBody] EasyMoveSuiteConfigRequestDto requestDto)
        {
            EasyMoveSuiteConfigPutDto putDto = requestDto.As<EasyMoveSuiteConfigPutDto>();
            putDto.EasyMoveSuiteConfigId = easyMoveSuiteConfigId;
            return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.Update(this.Admin, putDto));
        }
        #endregion

        #region 删除便捷搬家套餐配置
        /// <summary>
        ///  删除便捷搬家套餐配置
        /// </summary>
        /// <param name="easyMoveSuiteConfigId">便捷搬家套餐配置Id</param>
        /// <response code="204">删除便捷搬家套餐配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{easy_move_suite_config_id}")]
        [Log("删除便捷搬家套餐配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "easy_move_suite_config_id")] int easyMoveSuiteConfigId)
        {
            this.easyMoveSuiteConfigService.Delete(this.Admin, easyMoveSuiteConfigId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取便捷搬家套餐配置
        /// <summary>
        ///  获取便捷搬家套餐配置
        /// </summary>
        /// <param name="easyMoveSuiteConfigId">便捷搬家套餐配置Id</param>
        /// <response code="200">获取便捷搬家套餐配置</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{easy_move_suite_config_id}")]
        [ProducesResponseType(typeof(EasyMoveSuiteConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "easy_move_suite_config_id")] int easyMoveSuiteConfigId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.Get(easyMoveSuiteConfigId));
        }
        #endregion

        #region 获取便捷搬家套餐配置列表
        /// <summary>
        ///  获取便捷搬家套餐配置列表
        /// </summary>
		/// <param name="countyCode">区县编码</param>
        /// <response code="200">获取便捷搬家套餐配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{county_code}")]
        [ProducesResponseType(typeof(EasyMoveSuiteConfigDto), 200)]
        public IActionResult List([FromQuery(Name = "county_code")] string countyCode)
        {
            return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.GetList(this.Admin.AgentRecord.AgentRecordId,countyCode));
        }
        #endregion

        #region 获取便捷搬家套餐配置（分页）
        /// <summary>
        ///  获取便捷搬家套餐配置（分页）
        /// </summary>
		/// <param name="suiteName">套餐名称</param>
		/// <param name="provinceCode">省份编码</param>
		/// <param name="cityCode">城市编码</param>
		/// <param name="countyCode">区县编码</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取便捷搬家套餐配置（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<EasyMoveSuiteConfigDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "suite_name")] string suiteName,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {

            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null)
            {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            return StatusCode((int)HttpStatusCode.OK, this.easyMoveSuiteConfigService.Query(agentRecordId, suiteName, provinceCode, cityCode, countyCode, enabled, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 启用/禁用便捷搬家套餐配置
        /// <summary>
        ///  启用/禁用便捷搬家套餐配置
        /// </summary>
        /// <param name="easyMoveSuiteConfigId">便捷搬家套餐配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用便捷搬家套餐配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{easy_move_suite_config_id}/{enabled}")]
        [Log("启用/禁用便捷搬家套餐配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "easy_move_suite_config_id")] int easyMoveSuiteConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
            {
                this.easyMoveSuiteConfigService.Enabled(this.Admin, easyMoveSuiteConfigId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.easyMoveSuiteConfigService.Disabled(this.Admin,easyMoveSuiteConfigId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}

